using System;
using System.Collections.Generic;
using Game500.ClientServerCommon.Src;
using Microsoft.Xna.Framework;

namespace Game500.Client.Src
{
  public class Background : Renderable
  {
    private readonly List<Sprite> myObstacles = new List<Sprite>();

    public Background(ResourceManager resource, Map currentMap)
    {
      LowBound = -currentMap.YOffset;

      foreach (Shape obstacle in currentMap.Objects)
      {
        var obstacleSprite = new Sprite(resource.GetTexture(obstacle.TextureName), obstacle.Width, obstacle.Height)
                               {
                                 Origin = new Vector2(0, 1),
                                 Position = obstacle.Position
                               };
        myObstacles.Add(obstacleSprite);
      }
    }

    public float LowBound { get; private set; }

    public override Renderable Clone()
    {
      throw new Exception("Backround not intended to be cloneable");
    }

    public override void Render(Renderer renderer)
    {
      foreach (Sprite obstacle in myObstacles)
      {
        renderer.RenderSprite(obstacle);
      }
    }
  }
}